package in.muton.panels.paginator.components.badges;

import in.muton.edushare.components.images.ProfileImage;
import in.muton.edushare.pages.EduShareBasePage;
import in.muton.edushare.pages.common.EdusharePanel;
import in.muton.edushare.pages.deptpages.DeptCourses;
import in.muton.edushare.pages.deptpages.DeptPage;
import in.muton.edushare.pages.deptpages.DeptPeople;
import in.muton.edushare.pages.deptpages.DeptUniv;
import in.muton.edushare.url.EntityPageParams;
import in.muton.panels.paginator.badgehelpers.course.DeptBadgeInterface;
import in.muton.panels.paginator.helpers.deletelinks.DeptDelete;

import org.apache.wicket.PageParameters;
import org.apache.wicket.behavior.SimpleAttributeModifier;
import org.apache.wicket.markup.html.CSSPackageResource;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.IModel;

import com.edushare.common.constants.ApplicationConstants;
import com.edushare.common.util.StringUtil;
import com.edushare.common.vo.Departments;

public class DeptBadge extends EdusharePanel {

	public DeptBadge(String id, EduShareBasePage page, IModel<Departments> model) {
		super(id, model, page);
		this.deptModel = model;
		init();
	}

	public DeptBadge(String id, EduShareBasePage page,
			IModel<Departments> model, DeptBadgeInterface dbi) {
		super(id, model, page);
		this.deptModel = model;
		this.dbi = dbi;
		init();
	}
	
	private void init(){
		PageParameters p = EntityPageParams.getParams(deptModel);
		add(CSSPackageResource.getHeaderContribution(DeptBadge.class,
				"badge.css"));
		Link<Void> l = new BookmarkablePageLink<Void>("imgLink",
				DeptPage.class, p);
		l.add(new ProfileImage("img", deptModel,
				ApplicationConstants.FILE_SUFFIX_ICON));
		add(l);

		l = new BookmarkablePageLink<Void>("nameLink", DeptPage.class, p);
		l.add(new Label("name", StringUtil.ellipsis(deptModel.getObject()
				.getDeptName(), ApplicationConstants.TAG_BADGE_CHAR_LIMIT)));
		l.add(new SimpleAttributeModifier("title", deptModel.getObject()
				.getDeptName()));
		add(l);
		add(new BookmarkablePageLink<Void>("univ", DeptUniv.class, p));
		add(new BookmarkablePageLink<Void>("course", DeptCourses.class, p));
		add(new BookmarkablePageLink<Void>("people", DeptPeople.class, p));
		add(new DeptDelete("delete", deptModel, dbi, this));
	}

	private IModel<Departments> deptModel = null;
	private DeptBadgeInterface dbi;

	private static final long serialVersionUID = 2800845336343420260L;
}
